﻿using UnityEngine;
using System.Collections;

public class DueMachineGun : WeaponMachineGun {

	public float BulletDistance = 0.4f;

	override public void Fire (Vector3 direction) {
		Debug.Log("DueMachineGun Fire.");
		if (bulletPrefab && cooldownTimerInS < 0.0f) {
			cooldownTimerInS = cooldownTimeInS;
			FireOneShot(gameObject.transform.position - gameObject.transform.right * BulletDistance * 0.5f);
			FireOneShot(gameObject.transform.position + gameObject.transform.right * BulletDistance * 0.5f);
		}
	}

	private void FireOneShot(Vector3 position) {
		GameObject bulletLeft = Instantiate<GameObject>(bulletPrefab);
		Bullet bulletComponent = bulletLeft.GetComponent<Bullet>();
		if (bulletComponent) {
			bulletComponent.SetTarget(TargetTag);
			bulletComponent.Lunch(position, gameObject.transform.forward);
		}
	}
}
